/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class ProductListExcelView extends AbstractExcelView {
	public void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"ProductList.xls\"");
		HSSFFont boldFont = workbook.createFont();
		boldFont.setBoldweight(700);
		HSSFCellStyle boldStyle = workbook.createCellStyle();
		boldStyle.setFont(boldFont);
		boldStyle.setBorderBottom(1);
		boldStyle.setBorderTop(1);
		boldStyle.setBorderLeft(1);
		boldStyle.setBorderRight(1);
		boldStyle.setAlignment(2);
		HSSFCellStyle norStyle = workbook.createCellStyle();
		norStyle.setBorderBottom(1);
		norStyle.setBorderTop(1);
		norStyle.setBorderLeft(1);
		norStyle.setBorderRight(1);
		HSSFSheet sheet = workbook.createSheet("list");
		HSSFRow r = sheet.createRow(0);
		HSSFCell c = r.createCell(0);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("类别"));
		c = r.createCell(1);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("材料编号"));
		c = r.createCell(2);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("品名规格"));
		c = r.createCell(3);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("计量单位"));
		c = r.createCell(4);
		c.setCellStyle(boldStyle);
		c.setCellValue(new HSSFRichTextString("备注"));
		List list = (List) model.get("list");

		for (int os = 0; os < list.size(); ++os) {
			Object[] objs = (Object[]) list.get(os);
			r = sheet.createRow(os + 1);
			c = r.createCell(0);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString((String) objs[7]));
			c = r.createCell(1);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString((String) objs[1]));
			c = r.createCell(2);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString((String) objs[2]));
			c = r.createCell(3);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString((String) objs[3]));
			c = r.createCell(4);
			c.setCellStyle(norStyle);
			c.setCellValue(new HSSFRichTextString((String) objs[6]));
		}

		ServletOutputStream arg13 = response.getOutputStream();
		workbook.write(arg13);
		arg13.flush();
		arg13.close();
	}
}